import 'package:flutter/material.dart';
import 'package:flutter_application_1/components/avatar_role_name.dart';
import 'package:flutter_application_1/components/comment_like_read.dart';
import 'package:flutter_application_1/config/app_colors.dart';
import 'package:flutter_application_1/models/song_model.dart';
import 'package:flutter_application_1/utils/utils.dart';

class SongCard extends StatelessWidget {
  final SongItem songItem;
  const SongCard({Key? key, required this.songItem}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.only(
        top: toRpx(context, 40),
        right: toRpx(context, 2),
        bottom: toRpx(context, 40),
        left: toRpx(context, 40),
      ),
      child: Row(
        children: [
          _songCover(),
          SizedBox(
            width: 8,
          ),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              _songContent(),
              SizedBox(
                height: 12,
              ),
              Align(
                alignment: Alignment.bottomLeft,
                child: Row(
                  children: [
                    Container(
                      width: 118,
                      child: AvatarRoleName(
                        coverPictureUrl: songItem.user.coverPictureUrl,
                        nickname: songItem.user.nickname,
                        type: songItem.user.type,
                      ),
                    ),
                    CommentLikeRead(
                      commentCount: songItem.commentCount,
                      thumbUpCount: songItem.thumbUpCount,
                      readCount: songItem.readCount,
                    ),
                  ],
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }

  Widget _songContent() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          "${songItem.cnName}",
          style: TextStyle(color: AppColors.active, fontSize: 16),
          maxLines: 1,
          overflow: TextOverflow.ellipsis,
        ),
        Text(
          "${songItem.enName}",
          style: TextStyle(color: AppColors.un3active, fontSize: 12),
          maxLines: 1,
          overflow: TextOverflow.ellipsis,
        ),
      ],
    );
  }

  Widget _songCover() {
    return SizedBox(
      width: 75,
      height: 75,
      child: Stack(
        fit: StackFit.expand,
        children: [
          ClipRRect(
            borderRadius: BorderRadius.circular(10),
            child: FadeInImage.assetNetwork(
              placeholder: 'assets/images/common/lazy-1.png',
              image: songItem.coverPictureUrl,
              fit: BoxFit.cover,
            ),
          ),
          Center(
            child: Image.asset(
              'assets/images/icons/tiny_video.png',
              width: 22,
              height: 22,
              color: Colors.white,
            ),
          )
        ],
      ),
    );
  }
}
